package com.ruoyi.common.utils;

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.RandomUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


public class IOUtil {

	public static final DecimalFormat DF0 = new DecimalFormat("#0");
	public static final DecimalFormat DF1 = new DecimalFormat("#0.0");
	public static final DecimalFormat DF2 = new DecimalFormat("#0.00");
	public static DecimalFormat df_int =new   DecimalFormat("#");

	public static BASE64Decoder decoder64=new BASE64Decoder();
	public static BASE64Encoder encoder64=new BASE64Encoder();
			
	public static IOUtil getIns() {
		return new IOUtil();
	}
	/**
	 * 打印map的值
	 * @param map
	 */
	public static void printMap(Map<String, Object> map)
	{
		for(String key : map.keySet())
		{
			System.out.println(key+"="+map.get(key));
		}
	}
	/**
	 * 打印list的值
	 * @param list
	 */
	public static void printList(List<Map<String, Object>> list)
	{
		for (int i = 0; i < list.size(); i++) {
			printMap(list.get(i));
		}
	}
	public static String getLastMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date); // 设置为当前时间
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
        date = calendar.getTime();
        String accDate = format.format(date);
        return accDate;
    }
	
	/**
	 * 64ENCODE字符串
	 * @param str
	 * @return
	 */
	public static String encodeStr_64(String str)
	{
		String text = str;
		if(StrKit.isBlank(str))return "";
		String res="";
		try {
			byte[] textByte = text.getBytes("UTF-8");
			res=encoder64.encode(textByte);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return res;
	}
	
	/**
	 * 64Decode字符串
	 * @param str
	 * @return
	 */
	public static String decodeStr_64(String str)
	{
		if(StrKit.isBlank(str))return "";
		String res="";
		try {
			byte[] textByte = decoder64.decodeBuffer(str);
			res=new String(textByte);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return res;
	}
	
	
	/**
	 * 格式化double数字，保留指定的小数点位数
	 * @param dou
	 * @param size
	 * @return
	 */
	public static String formatString(double dou,int size)
	{
		String res="";
		if(size==0)
		{
			res=DF0.format(dou);
		}else if(size==1)
		{
			res=DF1.format(dou);
		}else if(size==2)
		{
			res=DF2.format(dou);
		}else
		{
			res=dou+"";
		}
		return res;
	}
	
	/**
	 * 格式化double数字，保留指定的小数点位数
	 * @param dou
	 * @param size
	 * @return
	 */
	public static double formatDouble(double dou,int size)
	{
		String res="";
		if(size==0)
		{
			res=DF0.format(dou);
		}else if(size==1)
		{
			res=DF1.format(dou);
		}else if(size==2)
		{
			res=DF2.format(dou);
		}else
		{
			res=dou+"";
		}
		return Double.parseDouble(res);
	}

	/**
	 * 回传信息
	 * 
	 * @param response
	 * @param retStr
	 */
	public static void writeBack(HttpServletResponse response, String retStr) {
		try {
			response.setContentType("text/html;charset=UTF-8");
			PrintWriter pw = response.getWriter();
			pw.write(retStr);
			pw.close();
		} catch (Exception e) {
			retStr = "0";
			e.printStackTrace();
		}
	}

	/**
	 * 生成验证码
	 * @param length 验证码长度
	 * @return
	 */
	public static String getCode(int length){
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i=0;i<length;i++){
			sb.append(random.nextInt(9)+1);
		}

		return sb.toString();
	}

	/**
	 * 生成30位随机字符串
	 * @return
	 */
	public static String getId()
	{
		return getdate("yyyyMMddHHmmss")+getRandom(16);
	}

	/**
	 * 生成30位随机字符串
	 * @return
	 */
	public static String getId(int num)
	{
		return getdate("yyyyMMddHHmmss")+getRandom(num);
	}
	/**
	 * UUID
	 * 
	 * @return
	 */
	public static String getUUID() {
		return java.util.UUID.randomUUID().toString().replace("-", "");
	}

	/**
	 * 获取当前时间戳
	 * @return
	 */
	public static String getTime_String(){
		return new Date().getTime()+"";
	}
	/**
	 * 获取当前时间戳
	 * @return
	 */
	public static long getTime_long(){
		return new Date().getTime();
	}
	/**
	 * 获取时间戳
	 * @return
	 */
	public static long getTime_long(String time){
		Timestamp timestamp = Timestamp.valueOf(time);
		return timestamp.getTime();
	}
	/**
	 * 获取时间厝与当前时间 间隔豪秒数
	 * @param time
	 * @return
	 */
	public static long getSecendBetweenTime(String time)
	{
		long timel=Long.parseLong(time);
		long time1l=new Date().getTime();//当前时间
		return time1l-timel;
	}
	/**
	 * 根据给定格式和时间，返回date
	 * @param time
	 * @param timestamp
	 * @return
	 */
	public static Date getDateByString(String time,String timestamp)
	{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timestamp);
        Date date=null;
		try {
			date = simpleDateFormat.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return date;
	}
	
	/**
	 * 根据时间戳获取时间
	 * @param timestamp
	 * @return
	 */
	public static String getTimeByStamp(String timestamp)
	{
		String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(timestamp);
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        return res;
	}
	
	/**
	 * 根据给定格式返回时间
	 * 
	 * @param dataFormat
	 * @return
	 */
	public static String getdate(String dataFormat) {
		SimpleDateFormat df = new SimpleDateFormat(dataFormat); // 制定日期格式
		Calendar c = Calendar.getInstance();
		Date date = new Date();
		c.setTime(date);
		String validityDate = df.format(c.getTime()); // 返回String型的时间
//		System.out.println(validityDate);
		return validityDate;
	}

	/**
	 * 根据给定格式返回时间
	 * 
	 * @param dataFormat
	 * @param month
	 * @param day
	 * @return
	 */
	public static String getdate(String dataFormat, int month, int day) {
		SimpleDateFormat df = new SimpleDateFormat(dataFormat); // 制定日期格式
		Calendar c = Calendar.getInstance();
		Date date = new Date();
		c.setTime(date);
		c.add(Calendar.DAY_OF_MONTH, day);
		c.add(Calendar.MONTH, month); // 将当前日期加一个月
		String validityDate = df.format(c.getTime()); // 返回String型的时间
//		System.out.println(validityDate);
		return validityDate;
	}

	/**
	 * 根据给定格式返回时间
	 * 
	 * @param dataFormat
	 * @param month
	 * @return
	 */
	public static String getdate(String dataFormat, int month) {
		SimpleDateFormat df = new SimpleDateFormat(dataFormat); // 制定日期格式
		df.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
		Calendar c = Calendar.getInstance();
		Date date = new Date();
		c.setTime(date);
		c.add(Calendar.MONTH, month); // 将当前日期加一个月
		String validityDate = df.format(c.getTime()); // 返回String型的时间
		return validityDate;
	}
	/**
	 * 返回当前时间的前几分钟
	 * @param minute
	 * @return
	 */
	public static String getTimeByMinute(int minute) {

        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.MINUTE, -minute);

        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());

    }
	/**
	 * 返回当前时间的后几分钟
	 * @param minute
	 * @return
	 */
	public static String getAfterTimeByMinute(int minute) {

        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.MINUTE, minute);

        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());

    }

	/**
	 * 获取几位随机数
	 * 
	 * @param num
	 * @return
	 */
	public static String getRandom(int num) {
		StringBuffer res = new StringBuffer((1+RandomUtils.nextInt(0,8))+"");
		for (int i = 1; i < num; i++) {
			res.append(RandomUtils.nextInt(0,9)) ;
		}
		return res.toString();
	}
	
	/**
	 * 获取几位随机数
	 * 
	 * @param num
	 * @return
	 */
	public static String getRandom_sms(int num) {
		String res = "";
		res=res+(1+RandomUtils.nextInt(0,8));
		for (int i = 1; i < num; i++) {
			res = res + RandomUtils.nextInt(0,9);
		}
		return res;
	}
	/**
	 * 随机取DOUBLE
	 * @param min
	 * @param max
	 * @return
	 */
	public static double nextDouble(double min, double max){
        if (max < min) {
        	return min;
        }
        if (min == max) {
            return min;
        }
        return min + ((max - min) * new Random().nextDouble());
	}
	/**
	 * 过滤传入字符串的敏感字符
	 * 
	 * @param str
	 * @return
	 */
	public static String fileStr(String str) {
		if (str != null && !str.equals("")) {
			str = str.replaceAll("<", "")// 匹配尖括号
					.replaceAll(">", "")// 匹配尖括号
					.replaceAll("@", "")// 匹配尖括号
					.replaceAll("$", "")// 匹配尖括号
					.replaceAll("%", "")// 匹配尖括号
					.replaceAll("\"", "")// 匹配双引号
					.replaceAll("\'", "")// 匹配单引号
					.replaceAll("\\(.*?\\)", "")// 匹配左右括号
					.replaceAll("[+]", "");// 匹配加号
		}
		return str;
	}

	/**
	 * 获取用户真实IP。可跳过代理
	 * 
	 * @param request
	 * @return
	 */
	public String getIP(HttpServletRequest request) {

		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}

		return ip;

	}

	public String judgeNull(String req) {
		return req == null ? "" : req;
	}

	/**
	 * 根据编码获取地市名称
	 * 
	 * @param code
	 * @return
	 */
	public String getCityByCode(String code) {
		String res = "";
		if ("0451".equals(code) || "451".equals(code)) {
			res = "哈尔滨";
		} else if ("0452".equals(code) || "452".equals(code)) {
			res = "齐齐哈尔";
		} else if ("0453".equals(code) || "453".equals(code)) {
			res = "牡丹江";
		} else if ("0454".equals(code) || "454".equals(code)) {
			res = "佳木斯";
		} else if ("0455".equals(code) || "455".equals(code)) {
			res = "绥化";
		} else if ("0456".equals(code) || "456".equals(code)) {
			res = "黑河";
		} else if ("0457".equals(code) || "457".equals(code)) {
			res = "大兴安岭";
		} else if ("0458".equals(code) || "458".equals(code)) {
			res = "伊春";
		} else if ("0459".equals(code) || "459".equals(code)) {
			res = "大庆";
		} else if ("0464".equals(code) || "464".equals(code)) {
			res = "七台河";
		} else if ("0467".equals(code) || "467".equals(code)) {
			res = "鸡西";
		} else if ("0468".equals(code) || "468".equals(code)) {
			res = "鹤岗";
		} else if ("0469".equals(code) || "469".equals(code)) {
			res = "双鸭山";
		}
		return res;
	}

	/**
	 * 将字符串类型的数据，从第一个DATE格式，转换为第二个DATE格式
	 * 
	 * @param Str
	 * @param dateFormatBefor
	 * @param dateFormatAfter
	 */
	public String strDateFormat(String Str, String dateFormatBefor,
			String dateFormatAfter) {
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormatBefor);
		SimpleDateFormat dff = new SimpleDateFormat(dateFormatAfter);// 设置日期格式
		Date date = null;
		try {
			date = sdf.parse(Str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dff.format(date);
	}

	/**
	 * MD5加密
	 * 
	 * @param s
	 * @return
	 */
	public static final String MD5(String s) {
		char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'A', 'B', 'C', 'D', 'E', 'F' };
		try {
			byte[] btInput = s.getBytes();

			MessageDigest mdInst = MessageDigest.getInstance("MD5");

			mdInst.update(btInput);

			byte[] md = mdInst.digest();

			int j = md.length;
			char[] str = new char[j * 2];
			int k = 0;
			for (int i = 0; i < j; i++) {
				byte byte0 = md[i];
				str[(k++)] = hexDigits[(byte0 >>> 4 & 0xF)];
				str[(k++)] = hexDigits[(byte0 & 0xF)];
			}
			return new String(str);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * MD5加密,取前5-15位
	 * 
	 * @param s
	 * @return
	 */
	public static final String MD5_s10(String s) {
		String md5s=MD5(s);
		System.out.println("md5s:"+md5s);
		return md5s.substring(4, 10);
	}

	/**
	 * 获取2天之间的天数
	 * @param smdate
	 * @param bdate
	 * @return
	 * @throws ParseException
	 */
	public static int daysBetween(String smdate, String bdate)
			throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		cal.setTime(sdf.parse(smdate));
		long time1 = cal.getTimeInMillis();
		cal.setTime(sdf.parse(bdate));
		long time2 = cal.getTimeInMillis();
		double between_days = (time2 - time1) / 86400000.0D;
		return (int) Math.ceil(between_days);
	}
	/**
	 * 获取2天之间的天数
	 * @param smdate
	 * @param bdate
	 * @return
	 * @throws ParseException
	 */
	public static int daysBetween(String smdate, String bdate,String dateFormat)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		Calendar cal = Calendar.getInstance();
		double between_days = 1;
		try {
			cal.setTime(sdf.parse(smdate));
			long time1 = cal.getTimeInMillis();
			cal.setTime(sdf.parse(bdate));
			long time2 = cal.getTimeInMillis();
			between_days = (time2 - time1) / 86400000.0D;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return (int) Math.ceil(between_days);
	}
	/**
	 * map转JSON
	 * @param map
	 * @return
	 */
	public static String map2Json(Map<String, Object> map)
	{
		JSONObject jso=new JSONObject();
		for(String key:map.keySet())
		{
			try {
				jso.put(key, map.get(key));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return jso.toString();
	}

	/**
	 * 获取当前日期是星期几
	 * @return
	 */
	public static String getWeekOfDate() {
		Date dt=new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return w+"";
    }
	/**
	 * 按照概率判断结果
	 * @param persent
	 * @return
	 */
	public static boolean getGL(int persent)
	{
		boolean res=false;
		if(RandomUtils.nextInt(0,99)<=persent)res=true;
		return res;
	}
	/**
	 * 比较2个时间，如果1》2返回1，否则返回0
	 * @param DATE1
	 * @param DATE2
	 * @return
	 */
	public static boolean compare_date(String DATE1, String DATE2) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() >= dt2.getTime()) {
                return true;
            } else {
                return false;
            } 
        } catch (Exception exception) {
            exception.printStackTrace();
            return false;
        }
    }
	 /*
     * 中文转unicode编码
     */
    public static String gbEncoding(final String gbString) {
        char[] utfBytes = gbString.toCharArray();
        String unicodeBytes = "";
        for (int i = 0; i < utfBytes.length; i++) {
            String hexB = Integer.toHexString(utfBytes[i]);
            if (hexB.length() <= 2) {
                hexB = "00" + hexB;
            }
            unicodeBytes = unicodeBytes + "\\u" + hexB;
        }
        return unicodeBytes;
    }
    /*
     * unicode编码转中文
     */
    public static String decodeUnicode(final String dataStr) {
        int start = 0;
        int end = 0;
        final StringBuffer buffer = new StringBuffer();
        while (start > -1) {
            end = dataStr.indexOf("\\u", start + 2);
            String charStr = "";
            if (end == -1) {
                charStr = dataStr.substring(start + 2, dataStr.length());
            } else {
                charStr = dataStr.substring(start + 2, end);
            }
            char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
            buffer.append(new Character(letter).toString());
            start = end;
        }
        return buffer.toString();
    }
    
   

	/**
	 * 过滤敏感字符
	 * @param str
	 * @return
	 */
	public static String fileMGStr(String str)
	{
		String[] fileStrArr={};
		if(StrKit.isBlank(str))return "";
		for(int i=0;i<fileStrArr.length;i++)
		{
			if(str.contains(fileStrArr[i]))str=str.replace(fileStrArr[i], "*");
		}
		return str;
	}
	/**
	 * 遍历MAP
	 * @param map
	 */
	public static void loopMap(Map<String, Object> map)
	{
		if(map!=null)
		{
			for(String key:map.keySet())
			{
				System.out.println("key is :"+key+"   value is :"+map.get(key));
			}
		}else{
			System.out.println("map is null");
			
		}
	}
	
	/**
	 * 数字转字母
	 * @param num
	 * @return
	 */
	public static String num2Letter(int num){
		String res="A";
		if(num==1)return "A";
		if(num==2)return "B";
		if(num==3)return "C";
		if(num==4)return "D";
		if(num==5)return "E";
		if(num==6)return "F";
		if(num==7)return "G";
		if(num==8)return "H";
		if(num==9)return "I";
		if(num==10)return "J";
		if(num==11)return "K";
		if(num==12)return "L";
		if(num==13)return "M";
		if(num==14)return "N";
		if(num==15)return "O";
		if(num==16)return "P";
		if(num==17)return "Q";
		if(num==18)return "R";
		if(num==19)return "S";
		if(num==20)return "T";
		if(num==21)return "U";
		if(num==22)return "V";
		if(num==23)return "W";
		if(num==24)return "X";
		if(num==25)return "Y";
		if(num==26)return "Z";
		return res;
	}

	/**
	 * 获取全部字母
	 * @return
	 */
	public static List<String> getZM()  
    {  
		List<String> list=new ArrayList<String>();
        int firstEnglish, lastEnglish;  
        char firstE = 'A', lastE = 'Z';      //获取首字母与末字母的值  
           
        firstEnglish = firstE;  
        lastEnglish = lastE;  
           
        for(int i = firstEnglish; i <= lastEnglish; ++i)  
        {  
            char uppercase, lowercase;   
               
            uppercase = (char)i;  
            lowercase = (char)(i + 32);  
            list.add(uppercase+"");
//            System.out.print(" " + uppercase + lowercase);  
        }  
           
        return list;
    } 
	
	/**
	 * 从2个时间中间随机取一天，年月日
	 * @param begTime
	 * @param endTime
	 */
	public static String getRandomYMD(String begTime,String endTime)
	{
		String res="";
		
		try {
			Date d1 = new SimpleDateFormat("yyyy-MM-dd").parse(begTime);
			Date d2 = new SimpleDateFormat("yyyy-MM-dd").parse(endTime);//定义结束日期
			int dayBetween=(int) ((d2.getTime()-d1.getTime())/ (1000*3600*24));
			Calendar dd = Calendar.getInstance();//定义日期实例
			dd.setTime(d1);
			dd.add(Calendar.DAY_OF_MONTH, RandomUtils.nextInt(0,dayBetween));
			res=new SimpleDateFormat("yyyy-MM-dd").format(dd.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return res;
	}
	/**
	 * 返回2个给定时间相隔的时间，单位：秒,入参格式固定为:yyyy-MM-dd HH:mm:ss
	 * @param dateS 
	 * @param dateE
	 * @return
	 */
	public static int getSecBetween2(String dateS,String dateE)
	{
		int res=0;
		try {
			Date d1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateS);
			Date d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateE);//定义结束日期
			res=(int) ((d2.getTime()-d1.getTime())/1000);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return res;
	}
	/**
	 * 返回2个给定时间相隔的时间，单位：秒
	 * @param dateS
	 * @param dateE
	 * @return
	 */
	public static int getSecBetween2(String dateS,String dateE,String dateFormat)
	{
		int res=0;
		try {
			Date d1 = new SimpleDateFormat(dateFormat).parse(dateS);
			Date d2 = new SimpleDateFormat(dateFormat).parse(dateE);//定义结束日期
			res=(int) ((d2.getTime()-d1.getTime())/1000);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return res;
	}
	/**
	 * 获取随机时间:时：分：秒
	 * @return
	 */
	public static String getRandomTime(String day)
	{
		String res="";
		int hour=6+RandomUtils.nextInt(0,16);
		int min=RandomUtils.nextInt(0,60);
		int sec=RandomUtils.nextInt(0,60);
		res=(hour<10?"0"+hour:hour)+":"+(min<10?"0"+min:min)+":"+(sec<10?"0"+sec:sec);
		return day+" "+res;
	}
	/**
	 * 获取随机时间   日:时：分：秒
	 * @return
	 */
	public static String getRandomTimeByMonth(String month)
	{
		String res="";
		int day=1+RandomUtils.nextInt(0,23);
		int hour=6+RandomUtils.nextInt(0,16);
		int min=RandomUtils.nextInt(0,60);
		int sec=RandomUtils.nextInt(0,60);
		res=(hour<10?"0"+hour:hour)+":"+(min<10?"0"+min:min)+":"+(sec<10?"0"+sec:sec);
		return month+"-"+day+" "+res;
	}
	/**
	 * 返回给定时间之后的多少分钟，秒钟
	 * @param minute
	 * @return
	 */
	public static String getAfterTimeByMinute(String dateStr,int minute,int sec) {
		Calendar calendar = Calendar.getInstance();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date=sdf.parse(dateStr);
			
			calendar.setTime(date);
			calendar.add(Calendar.MINUTE, minute);
			calendar.add(Calendar.SECOND, sec);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());

    }
	
	/**
	 * 返回给定时间之后的多少秒钟
	 * @return
	 */
	public static String getAfterTimeBySec(String dateStr,int sec) {
		Calendar calendar = Calendar.getInstance();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date=sdf.parse(dateStr);
			
			calendar.setTime(date);
			calendar.add(Calendar.MINUTE, sec);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());

    }
	
	/**
	 * 获取时间厝与当前时间 间隔豪秒数
	 * @param time 格式：yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static long getSecendBetweenTime_format(String time)
	{
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		//设置要读取的时间字符串格式
		Date date;
		Long timestamp=(long) 0;
		try {
			date = format.parse(time);
			//转换为Date类
			timestamp=date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		long time1l=new Date().getTime();//当前时间
		return time1l-timestamp;
	}
	
	/**
	 * 返回给定时间之后的多少天
	 * @return
	 */
	public static String getAfterTimeByDay(String dateStr,int day) {
		Calendar calendar = Calendar.getInstance();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date=sdf.parse(dateStr);
			
			calendar.setTime(date);
			calendar.add(Calendar.DAY_OF_MONTH, day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());

    }
	/**
	 * 返回给定时间之后的多少天
	 * @return
	 */
	public static String getAfterTimeByDay_format(String dateFormat,int day) {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		Date date=new Date();
		
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, day);
			
        return new SimpleDateFormat(dateFormat).format(calendar.getTime());

    }
	/**
	 * 返回给定时间之后的多少月
	 * @return
	 */
	public static String getAfterTimeByMonth(String dateStr,int month) {
		Calendar calendar = Calendar.getInstance();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date=sdf.parse(dateStr);
			
			calendar.setTime(date);
			calendar.add(Calendar.MONTH, month);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());

    }
	/**
	 * 返回给定时间之后的多少月
	 * @return
	 */
	public static String getAfterTimeByMonth_m(String dateStr,int month) {
		Calendar calendar = Calendar.getInstance();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			Date date=sdf.parse(dateStr);
			
			calendar.setTime(date);
			calendar.add(Calendar.MONTH, month);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return new SimpleDateFormat("yyyy-MM").format(calendar.getTime());

    }
	/**
	 * 根据数据取稍微大一点的整数
	 * @param l
	 */
	public static String getBigInt(String l)
	{
		int firstN = Integer.parseInt(l.subSequence(0, 1)+"") ;
		String length=(int)(Double.parseDouble(l))+"";
		String res=(firstN+1)+"";
		for(int i=0;i<length.length()-1;i++)
		{
			res=res+0;
		}
		return res;
	}
	
	
	/**

	* 返回首字母

	* @param strChinese

	* @param bUpCase

	* @return

	*/

	   public static String getPYIndexStr(String strChinese, boolean bUpCase){

	       try{

	           StringBuffer buffer = new StringBuffer();

	           byte b[] = strChinese.getBytes("GBK");//把中文转化成byte数组

	           for(int i = 0; i < b.length; i++){

	               if((b[i] & 255) > 128){

	                   int char1 = b[i++] & 255;

	                   char1 <<= 8;//左移运算符用“<<”表示，是将运算符左边的对象，向左移动运算符右边指定的位数，并且在低位补零。其实，向左移n位，就相当于乘上2的n次方

	                   int chart = char1 + (b[i] & 255);

	                   buffer.append(getPYIndexChar((char)chart, bUpCase));

	                   continue;

	               }

	               char c = (char)b[i];

	               if(!Character.isJavaIdentifierPart(c))//确定指定字符是否可以是 Java 标识符中首字符以外的部分。

	                   c = 'A';

	               buffer.append(c);

	           }

	           return buffer.toString();

	       }catch(Exception e){

	           System.out.println((new StringBuilder()).append("\u53D6\u4E2D\u6587\u62FC\u97F3\u6709\u9519").append(e.getMessage()).toString());

	       }

	       return null;

	   }
	   /**

		* 返回首字母

		* @param strChinese

		* @param bUpCase

		* @return

		*/

		   public static String getPYIndexStr_first(String strChinese, boolean bUpCase){

		       try{

		           StringBuffer buffer = new StringBuffer();

		           byte b[] = strChinese.getBytes("GBK");//把中文转化成byte数组

		           for(int i = 0; i < b.length; i++){

		               if((b[i] & 255) > 128){

		                   int char1 = b[i++] & 255;

		                   char1 <<= 8;//左移运算符用“<<”表示，是将运算符左边的对象，向左移动运算符右边指定的位数，并且在低位补零。其实，向左移n位，就相当于乘上2的n次方

		                   int chart = char1 + (b[i] & 255);

		                   buffer.append(getPYIndexChar((char)chart, bUpCase));

		                   continue;

		               }

		               char c = (char)b[i];

		               if(!Character.isJavaIdentifierPart(c))//确定指定字符是否可以是 Java 标识符中首字符以外的部分。

		                   c = 'A';

		               buffer.append(c);

		           }

		           return buffer.toString().substring(0, 1);

		       }catch(Exception e){

		           System.out.println((new StringBuilder()).append("\u53D6\u4E2D\u6587\u62FC\u97F3\u6709\u9519").append(e.getMessage()).toString());

		       }

		       return null;

		   }

	   /**

	    * 得到首字母

	    * @param strChinese

	    * @param bUpCase

	    * @return

	    */

	   private static char getPYIndexChar(char strChinese, boolean bUpCase){

	       int charGBK = strChinese;

	       char result;

	       if(charGBK >= 45217 && charGBK <= 45252)

	           result = 'A';

	       else

	       if(charGBK >= 45253 && charGBK <= 45760)

	           result = 'B';

	       else

	       if(charGBK >= 45761 && charGBK <= 46317)

	           result = 'C';

	       else

	       if(charGBK >= 46318 && charGBK <= 46825)

	           result = 'D';

	       else

	       if(charGBK >= 46826 && charGBK <= 47009)

	           result = 'E';

	       else

	       if(charGBK >= 47010 && charGBK <= 47296)

	           result = 'F';

	       else

	       if(charGBK >= 47297 && charGBK <= 47613)

	           result = 'G';

	       else

	       if(charGBK >= 47614 && charGBK <= 48118)

	           result = 'H';

	       else

	       if(charGBK >= 48119 && charGBK <= 49061)

	           result = 'J';

	       else

	       if(charGBK >= 49062 && charGBK <= 49323)

	           result = 'K';

	       else

	       if(charGBK >= 49324 && charGBK <= 49895)

	           result = 'L';

	       else

	       if(charGBK >= 49896 && charGBK <= 50370)

	           result = 'M';

	       else

	       if(charGBK >= 50371 && charGBK <= 50613)

	           result = 'N';

	       else

	       if(charGBK >= 50614 && charGBK <= 50621)

	           result = 'O';

	       else

	       if(charGBK >= 50622 && charGBK <= 50905)

	           result = 'P';

	       else

	       if(charGBK >= 50906 && charGBK <= 51386)

	           result = 'Q';

	       else

	       if(charGBK >= 51387 && charGBK <= 51445)

	           result = 'R';

	       else

	       if(charGBK >= 51446 && charGBK <= 52217)

	           result = 'S';

	       else

	       if(charGBK >= 52218 && charGBK <= 52697)

	           result = 'T';

	       else

	       if(charGBK >= 52698 && charGBK <= 52979)

	           result = 'W';

	       else

	       if(charGBK >= 52980 && charGBK <= 53688)

	           result = 'X';

	       else

	       if(charGBK >= 53689 && charGBK <= 54480)

	           result = 'Y';

	       else

	       if(charGBK >= 54481 && charGBK <= 55289)

	           result = 'Z';

	       else

	           result = (char)(65 + (new Random()).nextInt(25));

	       if(!bUpCase)

	           result = Character.toLowerCase(result);

	       return result;

	   }
	   
	   
	   public static String getThisWeekMonday() {
	        Calendar cal = Calendar.getInstance();
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	        cal.setTime(new Date());
	        // 获得当前日期是一个星期的第几天
	        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
	        if (1 == dayWeek) {
	            cal.add(Calendar.DAY_OF_MONTH, -1);
	        }
	        // 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
	        cal.setFirstDayOfWeek(Calendar.MONDAY);
	        // 获得当前日期是一个星期的第几天
	        int day = cal.get(Calendar.DAY_OF_WEEK);
	        // 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
	        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
	        return sdf.format(cal.getTime());
	    }   
	   public static void main(String[] args) {

//		   for (int i = 0; i < 100; i++) {
//			   System.out.println(getCode(4));
//		   }

//		System.out.println(getLastMonth()+"-01");
//		String day=getAfterTimeByDay_format("yyyy-MM-dd",-1);
//		System.out.println(day);


//		System.out.println(getThisWeekMonday());
//		System.out.println(IOUtil.encodeStr_64("1#00000001#1698371327069#1111112222223333"));
		
		System.out.println(MD5("123456"));
//		System.out.println(IOUtil.getAfterTimeByDay(IOUtil.getdate("yyyy-MM-dd"), -7));
		
//		String today=IOUtil.getdate("yyyy-MM-dd");
//		String lastday=IOUtil.getAfterTimeByMonth(today, 3);
//		System.out.println(lastday);
//		System.out.println(IOUtil.getdate(IOUtil.getdate("yyyy-MM-dd"), 0, -1)+"00:00:00");
//		String stime=IOUtil.getAfterTimeByDay_format("yyyy-MM-dd",-1 )+" 00:00:00";
//		System.out.println(stime);
		
//		System.out.println(daysBetween("2020-01-01", "2020-03-01", "yyyy-MM-dd"));
		
//		System.out.println(getDateByString("2020-09-13 08:42:05", "yyyy-MM-dd HH:mm:ss"));
//		Calendar c = Calendar.getInstance();
//		int datenum=c.get(Calendar.DATE);
//		System.out.println(datenum);
//		System.out.println(getAfterTimeByMinute(-10).substring(11, 16));
		
		
//		System.out.println(IOUtil.getdate("yyyy-MM-dd HH:mm"));
//		System.out.println(IOUtil.getAfterTimeBySec(IOUtil.getdate("yyyy-MM-dd HH:mm:ss"), 60*24));
		
//		System.out.println(MD5_s10("20200304094734823240"));
		
//		System.out.println(getBigInt("1899.33"));
//		System.out.println(getTime_long());
//		System.out.println(getTimeByStamp("1582956959192"));
		
//		System.out.println(getPYIndexStr("我叫马文光", true).subSequence(0, 1));
		
//		System.out.println(getAfterTimeByMonth_m("2020-01", -2));
//		System.out.println( IOUtil.getAfterTimeByMonth(IOUtil.getdate("yyyy-MM-dd"), -11).substring(0,7));

//		System.out.println(getPYIndexStr_first("拉姆", true));
		
//		System.out.println(getFullSpell("你好啊aaadf"));
		
//		for (int i = 0; i < 60; i++) {
//			System.out.println(getRandom(6));
//		}
//		
//		System.out.println(new Date().getTime());
//		try {
//			Thread.sleep(100);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		System.out.println(new Date().getTime());
		
//		for(int i=0;i<50;i++){
//			int x=RandomUtils.nextInt(0, 3);
//			System.out.println(x);
//		}
		
//		System.out.println(IOUtil.getdate("mm:ss"));
//		for(int i=0;i<200;i++)
//		{
////			System.out.println(RandomUtils.nextInt(0,10));
//			System.out.println(nextDouble(0, 1));
////			System.out.println(getRandomDouble(2.22, 3.33));
////			System.out.println(getId().length());
//		}
//		System.out.println(gbEncoding("asdfjasd;fj/sdfjl"));
//		System.out.println(getAfterTimeByMinute(5));
		
	}
}
